package mysql

import (
	"gorm.io/gorm"
	user "online-medical-consultation/common/proto"
)

type Patient struct {
	gorm.Model
	UserId         int64  `gorm:"type:int(10)" json:"userId"`
	PatientName    string `gorm:"type:varchar(20)" json:"patientName"`     //患者姓名
	MedicalHistory string `gorm:"type:varchar(255)" json:"medicalHistory"` //患者病史
	PatientAge     int64  `gorm:"type:int(11)" json:"patientAge"`          //患者年龄
	PatientSex     int64  `gorm:"type:int(3)" json:"patientSex"`           // 1 男 2 女
	IdAllergy      int64  `gorm:"type:int(3)" json:"idAllergy"`            //是否过敏
}

func (p *Patient) CreatePatient(req *user.AddPatientReq) error {
	patient := &Patient{
		PatientName:    req.PatientName,
		MedicalHistory: req.MedicalHistory,
		PatientAge:     req.PatientAge,
		PatientSex:     req.PatientSex,
		IdAllergy:      req.IdAllergy,
	}
	err := DB.Create(&patient).Error
	if err != nil {
		return err
	}
	return nil
}
func (p *Patient) FindPatient(userId int64) (patient []*Patient, err error) {
	err = DB.Where("user_id=?", userId).Find(&patient).Error
	if err != nil {
		return nil, err
	}
	return patient, nil
}
